//
//  XWNewsCell.m
//  CGWSWW
//
//  Created by lanou3g on 16/8/17.
//  Copyright © 2016年 CXG. All rights reserved.
//

#import "XWNewsCell.h"
#import "XWNewsEntity.h"
#import <UIImageView+WebCache.h>
#import "CalculateHighTool.h"
@interface XWNewsCell ()
{
    CGFloat _imgHight;
}
/**
 *  图片
 */
@property (weak, nonatomic) IBOutlet UIImageView *imgIcon;
/**
 *  标题
 */
@property (weak, nonatomic) IBOutlet UILabel *lblTitle;
/**
 *  回复数
 */
@property (weak, nonatomic) IBOutlet UILabel *lblReply;
/**
 *  描述
 */
@property (weak, nonatomic) IBOutlet UILabel *lblSubtitle;
/**
 *  第二张图片（如果有的话）
 */
@property (weak, nonatomic) IBOutlet UIImageView *imgOther1;
/**
 *  第三张图片（如果有的话）
 */
@property (weak, nonatomic) IBOutlet UIImageView *imgOther2;


@end
@implementation XWNewsCell
- (void)setNewsModel:(XWNewsEntity *)newsModel
{

    if (_newsModel != newsModel) {
        _newsModel= nil;
        _newsModel = newsModel;
    }
    [self.imgIcon sd_setImageWithURL:[NSURL URLWithString:_newsModel.imgsrc] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    
       self.lblTitle.text = _newsModel.title;
    self.lblSubtitle.text = _newsModel.source;
    //如果回复太多就改变回复数字
    CGFloat replyCount = [_newsModel.replyCount integerValue];
    NSString *replyString;
    if (replyCount>10000) {
        replyString = [NSString stringWithFormat:@" %.1f跟帖",replyCount/10000];
    }else{
        replyString = [NSString stringWithFormat:@" %.0f跟帖",replyCount];
    }
    self.lblReply.text = replyString;
    if (_newsModel.imgextra.count==2) {
        [self.imgOther1 sd_setImageWithURL:[NSURL URLWithString:_newsModel.imgextra[0]] placeholderImage:[UIImage imageNamed:@"placeholder"]];
        [self.imgOther2 sd_setImageWithURL:[NSURL URLWithString:_newsModel.imgextra[1]] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    }

}


#pragma mark - /************************* 类方法返回可重用ID ***************************/
+ (NSString *)idForRow:(XWNewsEntity *)newsModel
{
    if (newsModel.hasHead && newsModel.photosetID) {
        return @"TopImageCell";
    }else if (newsModel.hasHead){
        return @"TopTxtCell";
    }else if (newsModel.imgType){
        return @"BigImageCell";
    }else if (newsModel.imgextra){
        return @"ImagesCell";
    }else{
        return @"NewsCell";
    }
    return nil;
}
//
#pragma mark - /************************* 类方法返回行高 ********************
+( CGFloat)hightForRow:(XWNewsEntity *)newsModel{
   XWNewsCell *cell =[[XWNewsCell alloc]init];
    CGFloat imgHigh = [CalculateHighTool heightForImageName:cell.newsModel.imgsrc allowWidth:cell.imgIcon.bounds.size.width];
    if (newsModel.hasHead &&newsModel.photosetID) {
        return imgHigh;
        
    }else if (newsModel.hasHead){
        return imgHigh+30;
    }
    else if (newsModel.imgType){
        return imgHigh+72;
    }else if (newsModel.imgextra){
        return imgHigh +36;
    }
    return 86;

}
@end
